<include file="Public/header1" title="文稿管理" />
<style type="text/css">
    a.success { color: #000;}
    .more .panel{display: none}
</style>
<div class="main">
    <div class="wrap">
        <include file="Public/sidebar" active="文稿管理" />
        <div class="content">
            <div class="nav">
                <div class="search">
                    <form id="search-form" action="{:U('index')}">
                    <input type="text" class="search-inner" name="title" value="{$Think.get.title}">
                    <div class="search-icon" id="search-btn">
                        <i></i>
                    </div>
                    </form>
                </div>
            </div>
            <table class="list">
                <thead>
                <tr>
                    <th style="width: 70px;"></th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>创建时间</th>
                    <th>文稿状态</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                <foreach name="articleList" item="val">
                <tr>
                    <td class="checkAll">
                        <?php if($val['state'] != 1) { ?>
                        <input name="aid" type="checkbox" value="{$val.id}" class="np" />
                        <?php } ?>
                    </td>
                    <td class="list-title"><a href="{:U('details')}?id={$val.id}">{$val.title}</a></td>
                    <td>{$val.realname}</td>
                    <td>{$val.create_time|date="Y-m-d H:i",###}</td>
                    <td>
                        <switch name="val.state">
                            <case value="-1"><span style='color:#ccc'>草稿</span></case>
                            <case value="0"><span style='color:blue'>待审核</span></case>
                            <case value="1"><span style='color:green'>通过</span></case>
                            <case value="2"><span style='color:gray'>审核中</span></case>
                            <case value="3"><span style='color:red'>打回</span></case>
                        </switch>
                    </td>
                    <?php if($val['state'] != 1) { ?>
                    <td class="more">
                        <?php if(session('is_admin') || session('is_type') == 1) { ?>
                            <?php if(in_array($val['column_id'], $channelIds)) { ?>
                            <div class="panel">
                                <ul class="ctrl">
                                    <switch name="val.state">
                                        <case value="-1">
                                            <!--<li><a href="{:U('Article/verify')}?id={$val.id}&state=1" data-id="{$val.id}" class="success">通过</a></li>-->
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                            <li><a href="javascript:;" data-id="{$val.id}" class="scs">通过</a></li>
                                            <li><a href="{:U('Article/verify')}?id={$val.id}&state=3">打回</a></li>
                                        </case>
                                        <case value="0">
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                            <li><a href="javascript:;" data-id="{$val.id}" class="scs">通过</a></li>
                                            <li><a href="{:U('Article/verify')}?id={$val.id}&state=3">打回</a></li>
                                        </case>
                                        <case value="2">
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                            <li><a href="javascript:;" data-id="{$val.id}" class="scs">通过</a></li>
                                            <li><a href="{:U('Article/verify')}?id={$val.id}&state=3">打回</a></li>
                                        </case>
                                        <case value="3">
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                            <li><a href="javascript:;" data-id="{$val.id}" class="scs">通过</a></li>
                                        </case>
                                    </switch>
                                    <li> <a href="{:U('Article/ajaxDelArticle')}?id={$val.id}" data-aid='{$val.id}'>删除</a></li>
                                </ul>
                                <div class="close"></div>
                            </div>
                            <?php } else { ?>
                            <div class="panel">
                                <ul class="ctrl">
                                    <switch name="val.state">
                                        <case value="-1">
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                        </case>
                                        <case value="0">
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                        </case>
                                        <case value="3">
                                            <li><a href="{:U('Article/verify')}?id={$val.id}&state=0">发布</a></li>
                                            <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                        </case>
                                    </switch>
                                    <li> <a href="{:U('Article/ajaxDelArticle')}?id={$val.id}" data-aid='{$val.id}'>删除</a></li>
                                </ul>
                                <div class="close"></div>
                            </div>
                            <?php } ?>
                        <?php } else { ?>
                        <div class="panel">
                            <ul class="ctrl">
                                <switch name="val.state">
                                    <case value="-1">
                                        <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                    </case>
                                    <case value="0">
                                        <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                    </case>
                                    <case value="3">
                                        <li><a href="{:U('Article/verify')}?id={$val.id}&state=0">发布</a></li>
                                        <li><a href="{:U('editArticle')}?id={$val.id}">编辑</a></li>
                                    </case>
                                </switch>
                                <li> <a href="{:U('Article/ajaxDelArticle')}?id={$val.id}" data-aid='{$val.id}'>删除</a></li>
                            </ul>
                            <div class="close"></div>
                        </div>
                        <?php } ?>
                    </td>
                    <?php } else { ?>
                    <td class="more">
                        <div class="panel">
                            <ul class="ctrl">
                                <li><a href="{:U('Article/details')}?id={$val.id}" target="_blank">预览</a></li>
                            </ul>
                            <div class="close"></div>
                        </div>
                    </td>
                    <?php } ?>
                </tr>
                </foreach>
                </tbody>
            </table>
            <div class="menu">
                <div class="checkAll pull-left"><input type="checkbox" id="checkAll"/></div>
                <div class="submenu pull-left">
                    <a class="btn" id="pass">通过</a>
                    <a class="btn" id="delall">删除</a>
                </div>
            </div>
            <div class="controls">
                <div class="pagers">
                    {$showpage}
                </div>

            </div>
        </div>
    </div>
</div>
<div class="overlay hidden"><div class="loading">正在处理文稿，请稍后...</div></div>

<script>
    $(function(){
        $("#checkAll").click(function(){
            if($(this).is(":checked")){
                $(".checkAll").find('input').prop("checked",true);
            }else{
                $(".checkAll").find('input').prop("checked",false);
            }
        });
        $(".list-title").ellipsis({
            row: 1
        })

        $('#pass').click(function () {
            var id=$('[name=aid]:checked').map(function(){
                return $(this).val();
            }).get().join()
            $('.overlay').removeClass('hidden');
            $.ajax({
               type: 'POST',
               url: '{:U("Article/verify")}?state=1',
               data: {"id":id},
               async: true,
               success: function (data) {
                   $('.overlay').addClass('hidden');
                   if(data.status == 1) {
                       alert(data.info);
                       window.location.reload();
                   } else {
                       alert('操作失败');
                   }
               }
            });

        });


        $('#delall').click(function(){
            if(confirm('是否确定删除？')){
                var id=$('[name=aid]:checked').map(function(){
                    return $(this).val();
                }).get().join()

                $.post('{:U("ajaxDelArticle")}',{"id":id},function(data){
                    if(data.status==1){
                        $('[name=aid]:checked').parents('tr').remove();
                    }
                })
            }
        });

        $('#search-btn').click(function () {
            $("#search-form").submit();
        });

        $(".more").click(function(e){
//            e.preventDefault();
//            e.stopPropagation();
            $(".panel").removeClass("active");
            $(this).find(".panel").addClass("active").show();
            $(".close").click(function (ev) {
                ev.preventDefault();
                ev.stopPropagation();
                $(this).closest(".panel").removeClass("active").hide();
            })
        })

        var loading;

        $('.scs').on('click', function () {
            var id = $(this).data('id');
            $.ajax({
                type: "GET",
                url: "{:U('Article/verify')}",
                async: true,
                data: "id=" + id + "&state=1",
                success: function(data, textStatus){
                    $('.overlay').addClass('hidden');
                    if(data.status == 1) {
                        alert('已成功签发到《掌上武汉》');
                        window.location.reload();
                    } else {
                        alert('稿件通过失败');
                    }
                },
                beforeSend: function (XMLHttpRequest) {
                    $('.overlay').removeClass('hidden');
                }
            });
        })
    })



</script>
<include file="Public/footer" />